package com.zzq.guli.service.edu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.zzq.guli.service.base.result.R;
import com.zzq.guli.service.edu.entity.Video;
import com.zzq.guli.service.edu.service.VideoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author ZZQ
 * @since 2024-04-12
 */

//@CrossOrigin
@RestController
@RequestMapping("admin/edu/video")
public class VideoController {


    @Autowired
    VideoService videoService;

    @RequestMapping("saveVideoInfo")
    public R saveVideoInfo(@RequestBody Video video){

        boolean save = videoService.save(video);

        if (save) {
            return R.ok().message("保存成功");
        } else {
            return R.error().message("保存失败");
        }

    }


    @DeleteMapping("removeById/{id}")
    public R removeById(@PathVariable String id){
        videoService.removeById(id);

        return R.ok().message("删除视频成功");

    }


    @GetMapping("getById/{id}")
    public R getById(@PathVariable String id){
        Video byId = videoService.getById(id);
        return R.ok().data("video",byId);

    }


    @RequestMapping("updateVideo")
    public R updateVideo(@RequestBody Video video){
        QueryWrapper<Video> videoQueryWrapper = new QueryWrapper<>();
        videoQueryWrapper.eq("chapter_id",video.getChapterId());
        videoQueryWrapper.eq("id",video.getId());
        boolean update = videoService.update(video, videoQueryWrapper);
        return R.ok().message("更新视频成功");
    }








}

